package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OrgAccbook;
import com.ruoyi.system.service.IOrgAccbookService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账簿_核算账簿Controller
 * 
 * @author ruoyi
 * @date 2025-09-08
 */
@Controller
@RequestMapping("/system/accbook")
public class OrgAccbookController extends BaseController
{
    private String prefix = "system/accbook";

    @Autowired
    private IOrgAccbookService orgAccbookService;

    @RequiresPermissions("system:accbook:view")
    @GetMapping()
    public String accbook()
    {
        return prefix + "/accbook";
    }

    /**
     * 查询账簿_核算账簿列表
     */
    @RequiresPermissions("system:accbook:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrgAccbook orgAccbook)
    {
        startPage();
        List<OrgAccbook> list = orgAccbookService.selectOrgAccbookList(orgAccbook);
        return getDataTable(list);
    }

    /**
     * 导出账簿_核算账簿列表
     */
    @RequiresPermissions("system:accbook:export")
    @Log(title = "账簿_核算账簿", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrgAccbook orgAccbook)
    {
        List<OrgAccbook> list = orgAccbookService.selectOrgAccbookList(orgAccbook);
        ExcelUtil<OrgAccbook> util = new ExcelUtil<OrgAccbook>(OrgAccbook.class);
        return util.exportExcel(list, "账簿_核算账簿数据");
    }

    /**
     * 新增账簿_核算账簿
     */
    @RequiresPermissions("system:accbook:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存账簿_核算账簿
     */
    @RequiresPermissions("system:accbook:add")
    @Log(title = "账簿_核算账簿", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrgAccbook orgAccbook)
    {
        return toAjax(orgAccbookService.insertOrgAccbook(orgAccbook));
    }

    /**
     * 修改账簿_核算账簿
     */
    @RequiresPermissions("system:accbook:edit")
    @GetMapping("/edit/{pkAccbook}")
    public String edit(@PathVariable("pkAccbook") String pkAccbook, ModelMap mmap)
    {
        OrgAccbook orgAccbook = orgAccbookService.selectOrgAccbookByPkAccbook(pkAccbook);
        mmap.put("orgAccbook", orgAccbook);
        return prefix + "/edit";
    }

    /**
     * 修改保存账簿_核算账簿
     */
    @RequiresPermissions("system:accbook:edit")
    @Log(title = "账簿_核算账簿", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrgAccbook orgAccbook)
    {
        return toAjax(orgAccbookService.updateOrgAccbook(orgAccbook));
    }

    /**
     * 删除账簿_核算账簿
     */
    @RequiresPermissions("system:accbook:remove")
    @Log(title = "账簿_核算账簿", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orgAccbookService.deleteOrgAccbookByPkAccbooks(ids));
    }
}
